#ifndef _V_GRAPHS_H_
#define _V_GRAPHS_H_

#include <dpmi.h>
#include <go32.h>
#include <sys\nearptr.h>
#include <stdio.h>
#include <stdlib.h>
#include "utypes.h"
#include "codepage.h"

/** @defgroup Video Video 
 * @{
 *
 * Entering/leaving/utility video functions
 */

/** @name Some Game defines */
/*@{*/ 
#define THICKNESS 12   ///<  thickness of the game border
#define BORDER_COLOR 3 ///<  color of border
#define RED_COLOR 4    ///<  red
/*@}*/ 

/*
 * there are two global variables, declared (but not defined) here
 */
extern int HRES;  /**< global variable with the horizontal resolution in pixels */
extern int VRES;  /**< global variable with the vertical resolution in pixels */


/** Enter graphics mode, enabling near pointers and mapping video physical memory
 * to program virtual address.
 *
 * Returns a generic pointer pointing to video memory address or NULL on error. 
 * "mode" specifies the VESA graphics mode to use, and
 * the mapping information is returned through "map".
 *
 * Also initializes two global variables, VRES and HRES,
 */
char * enter_graphics(int mode, __dpmi_meminfo *map);

/** Unmap video memory, disable near pointer and returns to text mode
 */
void leave_graphics(__dpmi_meminfo map);

/** Draws a pixel of color "color" at screen coordinates x, y at memory address "base"
 */
void set_pixel(int x, int y, int color, char *base);

/** Returns the pixel color at screen coordinates x, y at memory address "base"
 */
int get_pixel(int x, int y, char *base);

/** Set graphics memory at memory address "base" to "color".
 */
void clear_screen(char color, char *base);

/** Draw a line of color "color" between point (xi,yi) and (xf,yf) at memory address "base"
*/
void draw_line(int xi, int yi, int xf, int yf, int color, char *base);

/** Draw a frame of color "BORDER_COLOR" between point (xi,yi) with "width" * "height" at memory address "base"
*/
void draw_frame(int xi,int yi,int width, int heigth, char *base);

/** clear partial square between (xi, yi) and (xf, yf) at memory address "base"
*/
void clear_partial_screen(int xi, int yi, int xf, int yf,char*base);

/** draw string "str" at (x, y) with color fore_color and the back with back_color, scaling char_scale at address video_base
*/
void drawStringAt(char* str, int x, int y, int fore_color, int back_color, int char_scale, char *video_base, char *table);

/** draw char "c" at (x, y) with color fore_color and the back with back_color, scaling char_scale at address video_base
*/
void drawCharAt(char c, int x, int y, int fore_color, int back_color, int char_scale, char *video_base, char *table);

/** draw integer "num" at (x, y) with color fore_color and the back with back_color, scaling char_scale at address video_base
*/
void drawIntAt(int num, int x, int y, int fore_color, int back_color, int char_scale, char *video_base, char *table);

/** changes red color to border_color
*/
void clean_red(char* base);

/** counts pixels with color BORDER_COLOR
*/
int count_pixels(int xi,int yi,int xf, int yf,int color,char* base);

/** returns the HRES used in video mode
*/
int get_h();

/** returns the VRES used in video mode
*/
int get_v();

/** @} end of video */ 

#endif
